﻿using Lucene.Net.Documents;
using Lucene.Net.Search;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Tunynet.Search
{
    /// <summary>
    /// 搜索基类接口
    /// </summary>
   public  interface ISearchEngine
    {
        /// <summary>
        /// 重建索引
        /// </summary>
        /// <param name="indexDocuments"></param>
        /// <param name="isBeginning"></param>
        /// <param name="isEndding"></param>
        void RebuildIndex(IEnumerable<Document> indexDocuments, bool isBeginning, bool isEndding);

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="indexDocument"></param>
        /// <param name="reopen"></param>
        void Insert(Document indexDocument, bool reopen = true);

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="indexDocuments"></param>
        /// <param name="reopen"></param>
        void Insert(IEnumerable<Document> indexDocuments, bool reopen = true);

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <param name="fieldNameOfId"></param>
        /// <param name="reopen"></param>
        void Delete(string id, string fieldNameOfId, bool reopen = true);

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ids"></param>
        /// <param name="fieldNameOfId"></param>
        /// <param name="reopen"></param>
        void Delete(IEnumerable<string> ids, string fieldNameOfId, bool reopen = true);

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="indexDocument"></param>
        /// <param name="id"></param>
        /// <param name="fieldNameOfId"></param>
        /// <param name="reopen"></param>
        void Update(Document indexDocument, string id, string fieldNameOfId, bool reopen = true);

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="indexDocuments"></param>
        /// <param name="ids"></param>
        /// <param name="fieldNameOfId"></param>
        /// <param name="reopen"></param>
        void Update(IEnumerable<Document> indexDocuments, IEnumerable<string> ids, string fieldNameOfId, bool reopen = true);
        
        /// <summary>
        /// 搜索
        /// </summary>
        /// <param name="searchQuery"></param>
        /// <param name="filter"></param>
        /// <param name="sort"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        PagingDataSet<Document> Search(Query searchQuery, Filter filter, Sort sort, int pageIndex, int pageSize);

        /// <summary>
        /// 搜索
        /// </summary>
        /// <param name="searchQuery"></param>
        /// <param name="filter"></param>
        /// <param name="sort"></param>
        /// <param name="topNumber"></param>
        /// <returns></returns>
        IEnumerable<Document> Search(Query searchQuery, Filter filter, Sort sort, int topNumber);

        /// <summary>
        /// 获取索引大小
        /// </summary>
        /// <returns></returns>
        double GetIndexSize();

        /// <summary>
        /// 获取最后修改时间
        /// </summary>
        /// <returns></returns>
        DateTime GetLastModified();

    }
}
